[][src]Crate dispatch

Rust wrapper for Apple's Grand Central Dispatch (GCD).

GCD is an implementation of task parallelism that allows tasks to be submitted to queues where they are scheduled to execute.

For more information, see Apple's Grand Central Dispatch reference.

Serial Queues

Serial queues execute tasks serially in FIFO order. The application's main queue is serial and can be accessed through the Queue::main function.

use dispatch::{Queue, QueueAttribute};

let queue = Queue::create("com.example.rust", QueueAttribute::Serial);
queue.exec_async(|| println!("Hello"));
queue.exec_async(|| println!("World"));

Concurrent Queues

Concurrent dispatch queues execute tasks concurrently. GCD provides global concurrent queues that can be accessed through the Queue::global function.

Queue has two methods that can simplify processing data in parallel, foreach and map:

use dispatch::{Queue, QueuePriority};

let queue = Queue::global(QueuePriority::Default);

let mut nums = vec![1, 2];
queue.for_each(&mut nums, |x| *x += 1);
assert!(nums == [2, 3]);

let nums = queue.map(nums, |x| x.to_string());
assert!(nums[0] == "2");

Modules

ffi

Raw foreign function interface for libdispatch.

Structs

Group

A Grand Central Dispatch group.

GroupGuard

An RAII guard which will leave a Group when dropped.

Once

A predicate used to execute a closure only once for the lifetime of an application.

Queue

A Grand Central Dispatch queue.

Semaphore

A counting semaphore.

SemaphoreGuard

An RAII guard which will signal a Semaphore when dropped.

SuspendGuard

An RAII guard which will resume a suspended Queue when dropped.

WaitTimeout

An error indicating a wait timed out.

Enums

QueueAttribute

The type of a dispatch queue.

QueuePriority

The priority of a global concurrent queue.